#!/bin/sh
set -e

export PROJECT_PATH="${1}"
export PACKAGE_NAME="${2}"
export CONFIGURATION="${3}"
export IS_SIMULATOR="${4}"
echo "PROJECT_PATH : ${PROJECT_PATH}"
echo "PACKAGE_NAME : ${PACKAGE_NAME}"
echo "CONFIGURATION : ${CONFIGURATION}"
echo "IS_SIMULATOR : ${IS_SIMULATOR}"

# compile lib/index.cj
BUILD_TYPE="debug"
if [[ "$CONFIGURATION" == "Release" ]]; then
    BUILD_TYPE="release"
fi
bash $PROJECT_PATH/lib/build.sh $PROJECT_PATH $BUILD_TYPE $IS_SIMULATOR

# embed and sign dylibs
PACKAGE_PATH="$PROJECT_PATH/ios"
ruby $PACKAGE_PATH/link-embed-libraries.rb "$PACKAGE_PATH" "$PACKAGE_NAME"